{-# OPTIONS -Wall #-}

--------------------------------------------------------------------------------
-- |
-- Module      :  Lambola.IDL.PrettyIDLExpr
-- Copyright   :  (c) Stephen Tetley 2014
-- License     :  BSD3
--
-- Maintainer  :  stephen.tetley@gmail.com
-- Stability   :  unstable
-- Portability :  GHC
--
-- Precedence pretty printer for IDL const expressions.
-- 
--------------------------------------------------------------------------------

module Lambola.IDL.PrettyIDLExpr
  ( 
    unparse

  -- ** Precedence 15
  , bitwiseNotU
  , plusU
  , negateU

  -- ** Precedence 13
  , multiplyB
  , divideB
  , moduloB

  -- ** Precedence 12
  , addB
  , subtractB

  -- ** Precedence 11
  , leftShiftB
  , rightShiftB

  -- ** Precedence 8
  , bitwiseAndB

  -- ** Precedence 7
  , bitwiseXorB

  -- ** Precedence 6
  , bitwiseOrB

  ) where


import Text.PrettyExprHPJ                       -- package: pretty-expr-hpj

import Text.PrettyPrint.HughesPJ                -- package: pretty




-- | Assume C-like precendence and fixity.
-- 
-- C99 has maximum precedence of 16.
--
unparse :: DocE -> Doc
unparse = unparser $ makeUnparser 16



--------------------------------------------------------------------------------
-- Precedence 15


-- | Bitwise not.
-- 
-- > ~ (prefix 15)
--
bitwiseNotU             :: DocE -> DocE
bitwiseNotU             = Unary (prefix 15) (noSpace "~")


-- | Plus (unary plus).
-- 
-- > + (prefix 15)
--
plusU                   :: DocE -> DocE
plusU                   = Unary (prefix 15) (noSpace "+")


-- | Arithmetic negation.
-- 
-- > - (prefix 15)
--
negateU                :: DocE -> DocE
negateU                = Unary (prefix 15) (noSpace "-")


--------------------------------------------------------------------------------
-- Precedence 13

-- | Multiplication.
-- 
-- > * (infixl 13)
--
multiplyB               :: DocE -> DocE -> DocE
multiplyB               = Binary (infixL 13) (noSpace "*")

-- | Division.
-- 
-- > / (infixl 13)
--
divideB                 :: DocE -> DocE -> DocE
divideB                 = Binary (infixL 13) (noSpace "/")


-- | Modulus.
-- 
-- > % (infixl 13)
--
moduloB                 :: DocE -> DocE -> DocE
moduloB                 = Binary (infixL 13) (noSpace "%")


--------------------------------------------------------------------------------
-- Precedence 12

-- | Addition.
-- 
-- > + (infixl 12)
--
addB                    :: DocE -> DocE -> DocE
addB                    = Binary (infixL 12) (noSpace "+")

-- | Subtraction.
-- 
-- > - (infixl 12)
--
subtractB               :: DocE -> DocE -> DocE
subtractB              = Binary (infixL 12) (noSpace "-")


--------------------------------------------------------------------------------
-- Precedence 11

-- | Left shift.
-- 
-- > << (infixl 11)
--
leftShiftB              :: DocE -> DocE -> DocE
leftShiftB              = Binary (infixL 11) (noSpace "<<")

-- |  Right shift.
-- 
-- > >> (infixl 11)
--
rightShiftB             :: DocE -> DocE -> DocE
rightShiftB             = Binary (infixL 11) (noSpace ">>")




--------------------------------------------------------------------------------
-- Precedence 8


-- | Integer bitwise AND.
-- 
-- > & (infixl 8)
--
bitwiseAndB             :: DocE -> DocE -> DocE
bitwiseAndB             = Binary (infixL 8) (spaced "&")


--------------------------------------------------------------------------------
-- Precedence 7


-- | Integer bitwise XOR.
-- 
-- > ^ (infixl 7)
--
bitwiseXorB             :: DocE -> DocE -> DocE
bitwiseXorB             = Binary (infixL 7) (spaced "^")



--------------------------------------------------------------------------------
-- Precedence 6


-- | Integer bitwise OR.
-- 
-- > | (infixl 6)
--
bitwiseOrB              :: DocE -> DocE -> DocE
bitwiseOrB              = Binary (infixL 6) (spaced "|")